﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using com.cgWorkstudio.BIMP.Client.Properties;
using com.cgWorkstudio.BIMP.Library.vo;
using com.cgWorkstudio.BIMP.Library.uc;
using com.cgWorkstudio.BIMP.Client.vo;

namespace com.cgWorkstudio.BIMP.Client {
    public partial class Form_Main:CGClientForm {
        public Form_Main() {
            InitializeComponent();
            this.Height = 700;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.showTopPanel.MouseDown += new MouseEventHandler(MoveMessengerFormHandler);
            this.showLeftPanel.MouseDown += new MouseEventHandler(MoveMessengerFormHandler);
            this.showButtomPanel.MouseDown += new MouseEventHandler(MoveMessengerFormHandler);
            this.showRightPanel.MouseDown += new MouseEventHandler(MoveMessengerFormHandler);
            
            uC_LeftButton1.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton2.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton3.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton4.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton5.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton6.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton7.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton8.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton9.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton10.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
            uC_LeftButton11.OnLeftButtonClicked += new UC_LeftButton.OnLeftButtonClickedCallBack(uC_LeftButton1_OnLeftButtonClicked);
 
        }
        /// <summary>
        /// 点击左侧的按钮
        /// </summary>
        /// <param name="buttonId"></param>
        void uC_LeftButton1_OnLeftButtonClicked(UC_LeftButton leftButton) {
            showTabControl.SelectedIndex = 11;
            foreach(UC_LeftButton getButton in showLeftPanel.Controls) {
                getButton.unSelectButton();
            }
            leftButton.selectButton();
            switch(leftButton.Name) {
                case "uC_LeftButton1":  // 系统设置
                    fillCGMenuItem(CGMainMenu.系统设置);
                    break;
                case "uC_LeftButton2":  // 营业管理
                    fillCGMenuItem(CGMainMenu.营业管理);
                    break;
                case "uC_LeftButton3":  // 会员管理
                    fillCGMenuItem(CGMainMenu.会员管理);
                    break;
                case "uC_LeftButton4":  // 员工管理
                    fillCGMenuItem(CGMainMenu.员工管理);
                    break;
                case "uC_LeftButton5":  // 项目管理
                    fillCGMenuItem(CGMainMenu.项目管理);
                    break;
                case "uC_LeftButton6":  // 物品管理
                    fillCGMenuItem(CGMainMenu.物品管理);
                    break;
                case "uC_LeftButton7":  // 业绩管理
                    fillCGMenuItem(CGMainMenu.业绩管理);
                    break;
                case "uC_LeftButton8":  // 运营管理
                    fillCGMenuItem(CGMainMenu.运营管理);
                    break;
                case "uC_LeftButton9":  // 店务管理
                    fillCGMenuItem(CGMainMenu.店务管理);
                    break;
                case "uC_LeftButton10": // 短信中心
                    fillCGMenuItem(CGMainMenu.短信中心);
                    break;
                case "uC_LeftButton11": // 帮助中心
                    fillCGMenuItem(CGMainMenu.帮助中心);
                    break;
            }
        }

        private void fillCGMenuItem(List<CGMenuItem> menuItems) {
            uC_DataGridView1.Rows.Clear();
            uC_DataGridView1.RowTemplate.Height = 109;

            int nCell = -1;
            int nRow = -1;
            for(int nIndex = 0;nIndex < menuItems.Count;nIndex++) {
                if(nIndex % 6 == 0) {
                    uC_DataGridView1.Rows.Add();                    
                    nRow++;
                    nCell = -1;
                }
                nCell++;
                uC_DataGridView1.Columns[nCell].Width = 123;
                uC_DataGridView1[nCell,nRow].Value = menuItems[nIndex].CGButtonPic;
                uC_DataGridView1[nCell,nRow].Tag = menuItems[nIndex].CGButtonFlag;
            }
        }

        private void Form_Main_Load(object sender,EventArgs e) {
            showTabControl.Left = -6;
            showTabControl.Top = -23;

            showTabControl.Width += 16;
            //showMainPanel.Height += 139;
        }
        protected override void OnShown(EventArgs e) {
            base.OnShown(e);
            setDefaultPic();
            
            uC_LeftButton1_OnLeftButtonClicked(uC_LeftButton1); // 系统设置
        }

        // 设置默认的图片
        private void setDefaultPic() {
            showTopPanel.BackgroundImage = Resources.Pic_Fenhongse_Top;
            showLeftPanel.BackgroundImage = Resources.Pic_Fenhongse_Left_Main;
            showRightPanel.BackgroundImage = Resources.Pic_Fenhongse_Right;
            showButtom_Buttom_Panel.BackgroundImage = Resources.Pic_Fenhongse_Bottom;
        }

        private void uC_CloseButton1_Click(object sender,EventArgs e) {
            doParentAction(CGControllerType.Close);
        }

        private void uC_MiniumumButton1_Click(object sender,EventArgs e) {
            this.WindowState = FormWindowState.Minimized;
        }
        /// <summary>
        /// 处理点击按钮的操作
        /// </summary>
        /// <param name="buttonFlag">点击的按钮的标题</param>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uC_DataGridView1_OnCGMenuButtonClicked(string buttonFlag,object sender,DataGridViewCellMouseEventArgs e) {

        }
    }
}
